package com.jinbo.sxzq;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.annotation.Nullable;
/*
规则结束及棋子图鉴
 */
public class IntroductionActivity extends Activity {
    private GameRuleFragment gameRuleFragment;
    private ChessHandbookFragment chessHandbookFragment;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_introduction);
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.add(R.id.fragment_vessel,gameRuleFragment).commit();
        Button gameRule = findViewById(R.id.game_rule);
        Button chessbook = findViewById(R.id.chess_handbook);
        Button introductionExit = findViewById(R.id.introduction_exit);
        gameRule.setOnClickListener(onClickListener);
        chessbook.setOnClickListener(onClickListener);
        introductionExit.setOnClickListener(onClickListener);
    }

    final View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            switch (v.getId()) {
                case R.id.game_rule:
                    if (gameRuleFragment == null) {
                        gameRuleFragment = new GameRuleFragment();
                    }
                    fragmentTransaction.add(R.id.fragment_vessel,gameRuleFragment);
                    break;
                case R.id.chess_handbook:
                    if (chessHandbookFragment == null) {
                        chessHandbookFragment = new ChessHandbookFragment();
                    }
                    fragmentTransaction.add(R.id.fragment_vessel,chessHandbookFragment);
                    break;
                case R.id.introduction_exit:
                    finish();
            }
            fragmentTransaction.commit();
        }
    };
}
